local modimport = modimport
local AddRoomPreInit = AddRoomPreInit
GLOBAL.setfenv(1, GLOBAL)

local IsTheFrontEnd = rawget(_G, "TheFrontEnd") and rawget(_G, "IsInFrontEnd") and IsInFrontEnd()
if IsTheFrontEnd then
    -- modimport("main/strings")
    return
end

local AllLayouts = require("map/layouts").Layouts

local function AddPrefabNearMultiplayerPortal(layout_name)
    local data = AllLayouts[layout_name].layout["multiplayer_portal"][1]
    AllLayouts[layout_name].layout["beautiful_dream"] = {
        {
            x = data.x + (math.random() + 0.5) * (math.random() < 0.5 and 1 or -1),
            y = data.y + (math.random() + 0.5) * (math.random() < 0.5 and 1 or -1),
            width = data.width,
            height = data.height
        }
    }
end

AddPrefabNearMultiplayerPortal("DefaultStart")
AddPrefabNearMultiplayerPortal("DarknessStart")
AddPrefabNearMultiplayerPortal("DefaultPlusStart")
if AllLayouts["ti_setpiece"] then
    AddPrefabNearMultiplayerPortal("ti_setpiece")
end
